package com.daji.callback_and_lambda.callback_async_lambda_bifunction;

import java.util.function.Consumer;

/*
* 该案例是 callback_async_lambda的升级版！
* 这个案例进一步省略了代码，直接使用Java8给我们提供的函数式接口的包，甚至我们自己不用定义函数式接口！
* */
public class CallBackTest {
    public static void main(String[] args) throws InterruptedException {
        Server server = new Server();
        clientSendMsg(server,"Server,Hello~");
    }

    private static void clientSendMsg(Server server, String msg) throws InterruptedException {
        System.out.println("客户端：发送的消息为：" + msg);

        //lambda方式开线程
        new Thread(()->{
            //利用Java给我们提供的函数式接口包：
            Consumer function = (status) -> System.out.println("客户端：服务端回调状态为：" + status);
            server.getClientMsg(function,msg);

        }).start();

        System.out.println("客户端：异步发送成功");
        Thread.sleep(1 * 500);
        System.out.println("继续跑下面的流程");
        Thread.sleep(1 * 500);
        System.out.println("继续跑下面的流程");
        Thread.sleep(1 * 500);
        System.out.println("跑完了！");
    }
}
